<template>
	<view>
		<home v-if="active==1"></home>
		<account v-if="active==4"></account>
		<repair v-if="active==3"></repair>
		<u-tabbar :value="active" activeColor="#4F6FF6" inactiveColor="#AAAAAA" @change="change" :fixed="true"
			:placeholder="false" :safeAreaInsetBottom="true">
			<u-tabbar-item text="首页" icon="home" name="1"></u-tabbar-item>
			<u-tabbar-item text="扫码报修" icon="scan" name="2"></u-tabbar-item>
			<u-tabbar-item text="简易报修" :icon="active==3?'/static/images/repair.png':'/static/images/repair_no.png'"
				name="3"></u-tabbar-item>
			<u-tabbar-item text="我的" icon="account" name="4"></u-tabbar-item>
		</u-tabbar>
	</view>
</template>

<script>
	import home from "./home"
	import account from "./account"
	import repair from "./repair"
	export default {
		components: {
			home,
			account,
			repair
		},
		data() {
			return {
				active: '1',
			}
		},

		created() {

		},
		methods: {
			change(name) {
				if (name == 2) {
					uni.scanCode({
						success: (res) => {
							const data = decodeURIComponent(res.path)
							const arr = data.split('=')
							const deviceId = arr.length > 1 ? arr[arr.length - 1] : 0
							uni.showLoading({
								title: "请稍等"
							})
							this.$http.post('/data/api.auth.User/deviceVier', {
								id: deviceId
							}).then(rest => {
								uni.hideLoading()
								if (rest.data.device_status == 3) {
									this.$func.tips(rest.data.device_name + '已报废')
								} else {
									this.$func.toUrl('/pages_user/repair/add?id=' + deviceId)
								}
							}).catch(e => {
								uni.hideLoading()
							})
						}
					});
				} else {
					this.active = name
				}


			}

		}
	}
</script>

<style scoped lang="scss">
	.search {
		background-color: #4F6FF6;
		padding: 20rpx 0 90rpx;

		.input {
			margin: 0 20rpx;
			padding: 0 10rpx;
			height: 84rpx;
			background: rgba(246, 246, 246, 1);
			border-radius: 46px;


			input {
				// border: none;
				flex: 1;
				font-size: 14px;
				margin: 0 10rpx;
			}

			.btn {
				width: 156rpx;
				height: 68rpx;
				background: rgba(79, 111, 246, 1);
				border-radius: 34rpx;
				color: #FFFFFF;
				font-size: 30rpx;
			}

		}
	}

	.swiper {
		margin: -60rpx 20rpx 60rpx;


		height: 304rpx;
		background: rgba(255, 255, 255, 1);
		box-shadow: 0px 6rpx 12rpx rgba(0, 0, 0, 0.07);
		border-radius: 20rpx;
	}

	.index_title {
		margin: 0 20rpx;
	}

	.cards {
		margin: 20rpx;
		background: #FFFFFF;
		border-radius: 20rpx;
		flex-wrap: wrap;
		justify-content: flex-start;
		padding: 30rpx 0;

		.cards_son {
			width: 33.3333%;
			padding: 20rpx 0;

			flex-direction: column;
			// background: rgba(79, 111, 246, 1);
			border-radius: 20rpx;
			margin-bottom: 10px;
			font-size: 32rpx;
			color: #FFFFFF;

			.num {
				font-size: 40rpx;
				color: #4F6FF6;
			}

			.desc {
				font-size: 26rpx;
				color: #ADADAD;
			}

			&:nth-child(2) {
				.num {
					color: #F6B84F;
				}
			}

			&:nth-child(3) {
				.num {
					color: #0027CB;
				}
			}

			&:nth-child(4) {
				.num {
					color: #F68C4F;
				}
			}

			&:nth-child(5) {
				.num {
					color: #D81E06;
				}
			}
		}
	}

	.device_list {
		background: rgba(255, 255, 255, 1);
		border-radius: 20rpx;
		margin: 20rpx;
	}
</style>